package com.lcxw.hxzbadmin.dao.configmapper;

import com.lcxw.hxzbadmin.entity.pojo.Activity;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ActivityMapper {

    /**
     * 1、插入一条活动记录
     */
    @Insert({"INSERT INTO ywpd_activity (" ,
         "name, desc, link, picUrl, startTime, endTime, status  ",
         ") values (" ,
         "#{name}, #{desc}, #{link}, #{picUrl}, #{startTime}, #{endTime}, #{status} )"
    })
    int insert(Activity activity);

    /**
     * 2、通过id删除一条活动
     */
    @Delete({"DELETE FROM ywpd_activity WHERE id=#{id}"})
    int deleteById(int id);

    /**
     * 3、通过id查询一条活动记录
     */
    @Select({"SELECT * FROM ywpd_activity WHERE id=#{id}"})
    Activity selectById(int id);

    /**
     * 4、查询所有活动记录
     */
    @Select({"SELECT * FROM ywpd_activity"})
    List<Activity> selectAll();

    /**
     * 5、更新一条活动记录
     */
    @Update({"UPDATE ywpd_activity SET ",
        "name = #{name}, ",
        "desc = #{desc}, ",
        "link = #{link}, ",
        "picUrl = #{picUrl}, ",
        "startTime = #{startTime}, ",
        "endTime = #{endTime} ",
        "WHERE id = #{id} "
    })
    int updateById(Activity activity);

    /**
     * 6、动态查询个数
     */
    @Select("<script>" + "SELECT COUNT(*) FROM ywpd_activity WHERE "
        + "<if test='name!=null'>"
        + "name = #{name} and "
        + "</if>"
        + "<if test='startTime!=null'>"
        + "addTime &gt;= #{startTime} and "
        + "</if>"
        + "<if test='endTime!=null'>"
        + "addTime &lt;= #{endTime} and "
        + "</if>"
        + "<if test='status!=null'>"
        + "status=#{status} and "
        + "</if>"
        + "1=1"
        + "</script>")
    int selectCountDync(String name,String startTime,String endTime,String status);

    /**
     * 7、动态查询
     */
    @Select("<script>" + "SELECT COUNT(*) FROM ywpd_activity WHERE "
        + "<if test='name!=null'>"
        + "name = #{name} and "
        + "</if>"
        + "<if test='startTime!=null'>"
        + "addTime &gt;= #{startTime} and "
        + "</if>"
        + "<if test='endTime!=null'>"
        + "addTime &lt;= #{endTime} and "
        + "</if>"
        + "<if test='status!=null'>"
        + "status=#{status} and "
        + "</if>"
        + "1=1"
        + " LIMIT #{pageIndex},#{pageSize} "
        + "</script>")
    List<Activity> selectDync(String name,String startTime,String endTime,String status,int pageIndex,int pageSize);

}
